/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) 李文友 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef MODBUSIOMODULEDRIVER_H
#define MODBUSIOMODULEDRIVER_H
#include <qvector.h>
#include <qmap.h>
#include "modbusiomoduleconfig.h"
#include "modbus.h"

/**
 * @brief The ModbusIoModuleDriver class 驱动类
 */
class ModbusIoModuleDriver
{
public:
    ModbusIoModuleDriver(QString fileName ,int modbusIdIn
                         ,int *globalCurrentAliasIn, modbus_t *globalCurrentModbusMasterIn);
    ~ModbusIoModuleDriver();

public:
    int getModbusMaster(modbus_t* modbusMasterReturn);
//    int setModbusMaster(modbus_t* modbusMasterIn);
    int readDi(QVector<bool> & diReturn);
    int readAllDi(QVector<bool> & diReturn);
    int readDi(int diIndex,bool & diReturn);
    int readDo(QVector<bool> & doReturn);
    int readDo( int doIndex, bool & doReturn);
    int writeDo(QVector<bool> doValue);
    int writeDo( int doIndex,bool doValue);
    int connectPort();
    bool isInitialOkStatus();
    int getDiDoCount(int &diCounter,int &doCounter,int &aiCounter, int &aoCounter);
    int checkModbusMaster();

private:

    int initial(QString fileName);

public:
    int modbusId;

private:
    int* globalCurrentAlias;
    modbus_t* globalCurrentModbusMaster;

    ModbusIoModuleConfig *ioModuleConfig;
    modbus_t* modbusMaster;
    bool isInitialedOk;

    CommunicateParameter comParameter;
    IoModuleRegAddressInfo regAdd;
    E_VENDOR_ID vendorId;

    int diCount;
    int doCount;
    int aiCount;
    int aoCount;


};

#endif // MODBUSIOMODULEDRIVER_H
